package cn.cnlee.app.ui.user;

import android.view.View;
import android.widget.TextView;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import cn.cnlee.app.R;
import cn.cnlee.app.base.AbsLifecycleActivity;
import cn.cnlee.app.config.Constants;
import cn.cnlee.app.pojo.LoginVo;
import cn.cnlee.app.repository.UserRepository;
import cn.cnlee.app.vm.UserViewModel;
import cn.cnlee.arch.event.LiveBus;


public class UserLoginActivity extends AbsLifecycleActivity<UserViewModel> {

    @BindView(R.id.rl_title_bar)
    View titleBar;

    @BindView(R.id.tv_title)
    TextView titleTv;


    @BindView(R.id.iv_back)
    View backBtn;

    @Override
    public int getLayoutId() {
        return R.layout.user_login_activity_layout;
    }

    @Override
    protected void dataObserver() {
        ButterKnife.bind(this);
        titleTv.setText("用户登录");
        backBtn.setVisibility(View.VISIBLE);
        titleBar.setVisibility(View.VISIBLE);
        LiveBus.get().getChannel(UserRepository.EVENT_KEY_LOGIN).observe(this, loginDTO -> {
            //通知登录成功
            LiveBus.get().getChannel(Constants.LOGIN_ACTION_NOTIFY_KEY).postValue(loginDTO);
            finish();
        });
    }

    @OnClick({R.id.btn_login, R.id.iv_back})
    void btnClick(View v) {
        switch (v.getId()) {
            case R.id.btn_login:
                LoginVo loginVo = new LoginVo();
                loginVo.password = "123";
                mViewModel.login(loginVo);
                break;
            case R.id.iv_back:
                finish();
                break;
        }

    }
}
